/**
 * Created by yihua on 2017/3/22.
 */
$(document).ready(function () {
    $(':checkbox[name=flag]').each(function () {
        $(this).click(function () {
            if ($(this).is(':checked')) {
                console.log($(this).val())
                $(':checkbox[name=flag]').prop("checked", false);
                $(this).prop('checked', true);
                $('#silence_userid').val($(this).val());
            }
        });
    });
    $("#silenceuser").click(function () {
        $('#silenceModal').modal("show");
    });
    $("#silenceModal").on('show.bs.modal', function (e) {
        $("#silence_hour").select2();
        if (0 == $(':checkbox[name=flag]:checked').length) {
            toastr.error('请选择一个用户', '', {positionClass: 'toast-bottom-center'});
            return false;
        }
    })
    $("#silence_confirm").unbind('click').click(function () {
        ;
        var options = {
            url: '/api/user/usersilence',
            success: showResponse,  // post-submit callback
            dataType: 'json',
            type: 'post',
            data: {}
        };
        $("#silenceuserForm").ajaxSubmit(options);
    });
    function showResponse(responseText) {
        if (0 !== responseText.errno) {
            toastr.error(responseText.errmsg, '', {positionClass: 'toast-bottom-center'});
        }
        else {
            toastr.success('成功', '', {positionClass: 'toast-bottom-center'});
            $('#silenceModal').modal('hide');
            window.location.reload();
        }
    }

});